package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentFeignHystrixService;
import com.atguigu.springcloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.net.URI;
import java.util.List;

/**
 * @Author: robert.song
 * @Date: Created in 2021/7/21
 */
@RestController
@Slf4j
public class OrderController {
    @Resource
    private PaymentFeignService paymentFeignService;
    @Resource
    private PaymentFeignHystrixService paymentFeignHystrixService;
    @Resource
    private RestTemplate restTemplate;
    @GetMapping("/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        return paymentFeignService.getPaymentById(id);
    }
    @GetMapping("/get/hystrix/ok/{id}")
    public String getPaymentHystrixById(@PathVariable("id") Integer id){
        return paymentFeignHystrixService.paymentInfo_ok(id);
    }
    @GetMapping("/get/hystrix/timeout/{id}")
    public String getTimeoutPaymentHystrixById(@PathVariable("id") Integer id){
        return paymentFeignHystrixService.paymentInfo_timeOut(id);
    }
    @GetMapping("/timeoutDemo")
    public String timeouDemo(){
        return paymentFeignService.timeoutDemo();
    }
    @GetMapping("/payment/zipkin")
    public String paymentZipkin(){
        return restTemplate.getForObject("http://localhost:8001/payment/zipkin",String.class);
    }
}
